package com.aaa.behind.controller;


import com.aaa.behind.service.IEEmpInfoService;
import com.aaa.behind.service.IEExamineService;
import com.aaa.entity.EEmpInfo;
import com.aaa.entity.EExamine;
import com.aaa.util.PageInfo;
import com.aaa.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * <p>
 * 审查表 前端控制器
 * </p>
 *
 * @author whj
 * @since 2023-01-13
 */
@RestController
@RequestMapping("/e-examine")
public class EExamineController {


    @Autowired
    private IEExamineService examineService;

    @Autowired
    private IEEmpInfoService empInfoService;


    @PostMapping("getExamine")
    public Result selectAll(PageInfo pageInfo, EExamine eExamine,String startTime ,String endTime){

        return new Result(examineService.selectAll(pageInfo,eExamine,startTime,endTime));
    }

    @PostMapping("selectBusiness")
    public Result selectBusiness(){
        return new Result(examineService.selectBusiness());
    }


    @PostMapping("insertExamine")
    public Result insertExamine(EExamine eExamine, @ModelAttribute(value = "telephone") String telephone){
        EEmpInfo eEmpInfo = empInfoService.selectName(telephone);
        eExamine.setCheckman(eEmpInfo.getId());
        eExamine.setIsDeleted(0);
        LocalDateTime now = LocalDateTime.now();
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String format = dateTimeFormatter.format(now);
        eExamine.setGmtCreate(format);
        return new Result(examineService.saveOrUpdate(eExamine));
    }


    @PostMapping("deleteExamine/{id}")
    public Result deleteExamine(@PathVariable String id){
        return new Result(examineService.removeById(id));
    }
}

